package com.demo.spring.aop底层演示.demo;

import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//Test类在org.springframework.aop.framework.autoproxy里，为了可以调用受保护的方法
@Configuration
public class Config {

	@Bean
	// Advisor: 切面：一个通知+一个切点
	public Advisor advisor3(MethodInterceptor advice3) {
		AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
		pointcut.setExpression("execution(* foo())");
		return new DefaultPointcutAdvisor(pointcut, advice3);
	}
	
	@Bean
	// Advice: 一个通知
	public MethodInterceptor advice3() {
		return new MethodInterceptor() {

			@Override
			public Object invoke(MethodInvocation invocation) throws Throwable {
				System.out.println("advice3 before ...");
				Object result = invocation.proceed();
				System.out.println("advice3 after ...");
				return result;
			}
			
		};
	}
	
}
